define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'tongcheng/rider_withdraw/index' + location.search,
                    // add_url: 'tongcheng/rider_withdraw/add',
                    edit_url: 'tongcheng/rider_withdraw/edit',
                    // del_url: 'tongcheng/rider_withdraw/del',
                    // multi_url: 'tongcheng/rider_withdraw/multi',
                    // import_url: 'tongcheng/rider_withdraw/import',
                    table: 'tongcheng_rider_withdraw',
                }
            });

            var table = $("#table");

            // 在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
                let form = $("form", table.$commonsearch);

                $("input[name='zone_id']", form).addClass("selectpage").data("source", "tongcheng/zone/index").data("params", {"custom[status]": 1}).data("orderBy","id desc");
                $("input[name='rider_id']", form).addClass("selectpage").data("source", "tongcheng/rider/index").data("params", {"custom[status]": 1}).data("field", "real_name").data("orderBy","id desc");
                $("input[name='user_id']", form).addClass("selectpage").data("source", "user/user/index").data("field", "nickname").data("orderBy","id desc");

                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'zone_id', title: __('Zone_id'), visible: false,},
                        {
                          field: 'zone.name', title: __('Zone.name'), operate: false, formatter: function (value, row, index) {
                            return value + '(' + row.zone_id + ')';
                          }
                        },
                        {field: 'user_id', title: __('User_id'), visible: false},
                        {
                          field: 'user.nickname', title: __('User.nickname'), operate: false, formatter: function (value, row, index) {
                            return value + '(' + row.user_id + ')';
                          }
                        },
                        {field: 'rider_id', title: __('Rider_id'), visible: false},
                        {
                          field: 'rider.real_name', title: __('Rider.real_name'), operate: false, formatter: function (value, row, index) {
                            return value + '(' + row.rider_id + ')';
                          }
                        },
                        {field: 'kind', title: __('Kind'), searchList: {"WECHAT":__('WECHAT'),"ALIPAY":__('ALIPAY')}, formatter: Table.api.formatter.normal},
                        {field: 'account', title: __('Account'), operate: 'LIKE'},
                        {field: 'amount', title: __('Amount'), operate: false},
                        {field: 'hand_fee', title: __('hand_fee'), operate: false},
                        {field: 'actual', title: __('actual'), operate: false},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'audit_admin_id', title: __('Audit_admin_id'), visible: false},
                        {
                          field: 'admin.nickname', title: __('Admin.nickname'), operate: false, formatter: function (value, row, index) {
                            if (!row.audit_admin_id) {
                              return '-';
                            }
                            return value + '(' + row.audit_admin_id + ')';
                          }
                        },
                        {field: 'audit_remark', title: __('Audit_remark'), operate: 'LIKE'},
                        {field: 'audit_image', title: __('Audit_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'audit_time', title: __('Audit_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
